package org.teamswift.crow.rbac.security.permission;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.shiro.authz.Permission;
import org.teamswift.crow.rbac.enums.CrowResourceActions;
import org.teamswift.crow.rbac.enums.CrowRowPermissionLevel;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CrowPermission implements Permission, Serializable {

    private String action;

    private String resource;

    private CrowRowPermissionLevel rowPermissionLevel;

    @Override
    public boolean implies(Permission needPerm) {
        if(!(needPerm instanceof CrowPermission)) {
            return false;
        }
        CrowPermission perm = (CrowPermission) needPerm;

        if(!perm.getResource().equals(resource)) {
            return false;
        }

        return action.equals(perm.getAction());
    }
}
